package org.intrasearch.core.mapreduce;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.slf4j.Logger;

import java.util.HashMap;
import java.util.Map;

@Singleton
public class MapReduceServiceImpl implements MapReduceService
{
    private final Map<Object, MapReduce> keyToMapReduce = new HashMap<Object, MapReduce>();
    private final Logger logger;

    @Inject
    public MapReduceServiceImpl(Logger logger)
    {
        this.logger = logger;
    }

    public <I, K extends Comparable<?>, V extends Comparable<?>> MapReduce<I,K,V> mapReduceForKey(Object key)
    {
        if (!keyToMapReduce.containsKey(key))
        {
            keyToMapReduce.put(key, new MapReduceImpl(key, logger));
        }
        return keyToMapReduce.get(key);
    }
}
